﻿using AnesSystem.Services;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls.Operation.SX.PLZYY
{
    /// <summary>
    /// 麻醉单头部基本信息
    /// </summary>
    public partial class AnesRecordBaseInfoCtrl : UserControl
    {
        public AnesRecordBaseInfoCtrl()
        {
            InitializeComponent();
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Brqw = "病房";
            DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Qtjy = "ST段分析，心率变异分析";
            this.Loaded += AnesRecordBaseInfoCtrl_Loaded;
            zq.CheckChanged += zq_CheckChanged;
            jz.CheckChanged += jz_CheckChanged;
            asa1_ValuegetAnescored();
            nnis0_ValueGetAneth();
            FenJiCtrl_PropertyGetAneth();
        }
        private void AnesRecordBaseInfoCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            DateTime ssrqda = DataManager.Instance.CurrentPatientLink.Status.InRoomTime;
            string date = Convert.ToDateTime(ssrqda).ToString("yyyy-MM-dd");
            ssrq.Text = date;
           
            InteZqJz();
        }



        private void InteZqJz()
        {
            bool zqtrue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Zq;
            bool jztrue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Jz;

            if (zqtrue)
            {
                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Js = true;
            }
            else if (jztrue)
            {
                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Bjs = true;
            }

        }

        private void zq_CheckChanged(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl zqCheck = sender as CustomCheckBoxCtrl;

            bool zqtrue = zqCheck.IsChecked;
            if (zqtrue)
            {
                jss.Value = true;
            }
            else
            {
                jss.Value = false;
            }

        }
        private void jz_CheckChanged(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl jzCheck = sender as CustomCheckBoxCtrl;

            bool zqtrue = jzCheck.IsChecked;
            if (zqtrue)
            {
                jsf.Value = true;
            }
            else
            {
                jsf.Value = false;
            }

        }

        private void BindTextCtrl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            AnesMethodsWin anesMethodsCtrl = new AnesMethodsWin();
            DrugAndEventWindow.Instance.Content = anesMethodsCtrl;
            DrugAndEventWindow.Instance.ShowDialog();
        }
        private void setZhiKonXin()
        {

        }
        private void BindTextCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            if (fjhss.IsChecked)
            {
                DataManager.Instance.CurrentPatientLink.QualityPojo.Fjhecss = true;
            }
        }

        private void fjhss_CheckChanged(object sender, RoutedEventArgs e)
        {
            CustomCheckBoxCtrl check = sender as CustomCheckBoxCtrl;
            bool istrue = check.IsChecked;
            if (istrue)
            {
                DataManager.Instance.CurrentPatientLink.QualityPojo.Fjhecss = true;
            }
        }
        private void nnis0_ValueGetAneth()
        {
            List<string> nisList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "nnis1", "nnis2", "nnis3", "nnis4");
            string nisValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis;
            if (string.IsNullOrEmpty(nisValue) && nisList.Count != 0)
            {
                for (int i = 0; i < nisList.Count;i++)
                {
                    if (nisList[i].Equals("True"))
                    {
                        switch (i)
                        {
                            case 0:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis = "0";
                                break;
                            case 1:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis = "1";
                                break;
                            case 2:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis = "2";
                                break;
                            case 3:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis = "3";
                                break;
                        }
                    }
                    return;
                }
            }

        }
        private void FenJiCtrl_PropertyGetAneth()
        {
            List<string> knList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "fj");
            string knqdValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Knqd;
            if (string.IsNullOrEmpty(knqdValue) && knList.Count != 0)
            {
                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Knqd = knList[0];
            }

        }


        private void asa1_ValuegetAnescored()
        {
            List<string> arList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "asa1", "asa2", "asa3", "asa4", "asa5", "asa6");
            string asaValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level;
            if (string.IsNullOrEmpty(asaValue))
            {
                for (int i = 0; i < arList.Count; i++)
                {
                    if (arList[i].Equals("True"))
                    {
                        switch (i)
                        {
                            case 0:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅰ";
                                break;
                            case 1:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅱ";
                                break;
                            case 2:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅲ";
                                break;
                            case 3:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅳ";
                                break;
                            case 4:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅴ";
                                break;
                            case 5:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅵ";
                                break;

                        }
                        return;
                    }
                }
            }
        }

    }

}
